/*!
 * Ext JS Library 4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */

Ext.define('MyDesktop.App', {
    extend: 'Ext.ux.desktop.App',

    requires: [
            'Ext.window.MessageBox',
            'Ext.ux.desktop.ShortcutModel',
            'MyDesktop.SystemStatus',
            'MyDesktop.VideoWindow',
            'MyDesktop.GridWindow',
            'MyDesktop.TabWindow',
            'MyDesktop.AccordionWindow',
            'MyDesktop.Notepad',
            'MyDesktop.BogusMenuModule',
            'MyDesktop.BogusModule',
            'MyDesktop.Programacion',
        //        'MyDesktop.Blockalanche',
        'MyDesktop.Settings',
            'MyDesktop.Proyecto'
    ],

    init: function() {
        // custom logic before getXYZ methods get called...

        this.callParent();

        // now ready...
    },

    getModules: function() {
        var modules = [];
        for (var i = 0; i < titulodos; ++i) {
            //alert('new '+ titulotresx.getAt(i).get('getModule')+'()');
            modules.push(new MyDesktop[titulotresx.getAt(i).get('getModule')]());
        }
        return modules;
        //        return [
        //            //new MyDesktop.VideoWindow(),
        //            //new MyDesktop.Blockalanche(),
        //            new MyDesktop.SystemStatus(),
        //            //new MyDesktop.GridWindow(),
        //            //new MyDesktop.TabWindow(),
        //            new MyDesktop.AccordionWindow(),
        //            new MyDesktop.Notepad(),
        //            //new MyDesktop.BogusMenuModule(),
        //            new MyDesktop.Programacion(),
        //            //new MyDesktop.BogusModule(),
        //            new MyDesktop.Proyecto()
        //        ];
    },

    getDesktopConfig: function() {
        var me = this,
            ret = me.callParent();
        //alert(titulodos);
        var data = [];
        for (var i = 0; i < titulodos; ++i) {
            //alert(titulotresx.getAt(i).get('Modulo'));
            data.push({
                name: titulotresx.getAt(i).get('NomAplicacion'),
                iconCls: titulotresx.getAt(i).get('iconCls'),
                module: titulotresx.getAt(i).get('module')
            });
        }


        return Ext.apply(ret, {
            //cls: 'ux-desktop-black',

            contextMenuItems: [{
                    text: 'Change Settings',
                    handler: me.onSettings,
                    scope: me
                }
            ],

            shortcuts: Ext.create('Ext.data.Store', {
                model: 'Ext.ux.desktop.ShortcutModel',
                data: data
                //                data: [
                //                    { name: 'RRHH', iconCls: 'accordion-shortcut', module: 'acc-win' },
                //                    { name: 'QUEJAS RECLAMOS', iconCls: 'notepad-shortcut', module: 'notepad' },
                //                    { name: 'TRES W', iconCls: 'grid-shortcut', module: 'grid-win' },
                //                    { name: 'PROGRAMA CIONES', iconCls: 'programacion-shortcut', module: 'programacion'},
                //                    { name: 'CONTROL INVENTARIO', iconCls: 'inventario-shortcut', module: 'systemstatus'},
                //                    { name: 'MONIT PROYECTO', iconCls: 'cpu-shortcut', module: 'proyecto'}
                //                ]
            }),

            wallpaper: 'wallpapers/Blue-Sencha.jpg',
            wallpaperStretch: false
        });
    },

    // config for the start menu
    getStartConfig: function() {
        var img = "/Content/RRHH/Fotos/";
        var me = this,
            ret = me.callParent();
        var tpl = '<div class="search-item">' +
        //'<h3><span><img width="55" height="60" src="/Content/RRHH/Fotos/'+idPersona+'.jpg" /><br /></span>'+titulogeneral+'</h3>'+
        '<h3><span><img width="55" height="60" style="vertical-align:middle; background: url(Content/RRHH/Fotos/' + idPersona + '.jpg) center center, url(Content/RRHH/Fotos/default.png) #ddd center center; z-index: 10000;"/><br /></span>' + titulogeneral + '</h3>' +
            'Fotocheck: ' + fotocheck + '<br>' +
            tipodni + ': ' + ' ' + nroDI +
            '</div>';
        return Ext.apply(ret, {
            title: tpl, //titulogeneral+'<img width="55" height="60" src="/Content/RRHH/Fotos/'+Idpx+'.jpg+" />',
            iconCls: 'user',
            height: 300,
            toolConfig: {
                width: 100,
                items: [{
                        text: 'Configuracion',
                        iconCls: 'settings',
                        handler: me.onSettings,
                        scope: me
                    },
                        '-', {
                        text: 'Cerrar Cesión',
                        iconCls: 'logout',
                        handler: me.onLogout,
                        scope: me
                    }
                ]
            }
        });
    },

    getTaskbarConfig: function() {
        var ret = this.callParent();

        return Ext.apply(ret, {
            quickStart: [
                //{ name: 'Accordion Window', iconCls: 'accordion', module: 'acc-win' },
                //{ name: 'Grid Window', iconCls: 'icon-grid', module: 'grid-win' }
            ],
            trayItems: [{
                    xtype: 'trayclock',
                    flex: 1
                }
            ]
        });
    },

    onLogout: function() {
        Ext.Msg.confirm('Logout', '¿Está seguro que desea cerrar la sesión?');
    },

    onSettings: function() {
        var dlg = new MyDesktop.Settings({
            desktop: this.desktop
        });
        dlg.show();
    }
});